package cn.aohan.common.exception;


import java.text.MessageFormat;

/**
 * 业务异常
 *
 * @author 傲寒
 * @since 2024/03/20
 */
public class BizException extends RuntimeException {

    private String code;

    private String message;


    public String getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public BizException(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public BizException(String code, String message, Exception e) {
        super(message, e);
        this.code = code;
        this.message = message;
    }

    public BizException(String code, Exception e) {
        super(e);
        this.code = code;
    }

    public BizException(String code, String msg, Exception e, Object... params) {
        super(e);
        String message = MessageFormat.format(msg, params);
        this.code = code;
        this.message = message;
    }

    public BizException(String code, String msg, Object... params) {
        String message = MessageFormat.format(msg, params);
        this.code = code;
        this.message = message;
    }

    public BizException(String msg, Object... params) {
        String message = MessageFormat.format(msg, params);
        this.code = "ERROR";
        this.message = message;
    }

    public BizException(String message) {
        this("ERROR", message);
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof BizException)) {
            return false;
        } else {
            BizException other = (BizException) o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$code = this.getCode();
                Object other$code = other.getCode();
                if (this$code == null) {
                    if (other$code != null) {
                        return false;
                    }
                } else if (!this$code.equals(other$code)) {
                    return false;
                }

                Object this$message = this.getMessage();
                Object other$message = other.getMessage();
                if (this$message == null) {
                    if (other$message != null) {
                        return false;
                    }
                } else if (!this$message.equals(other$message)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof BizException;
    }


    public String toString() {
        return "BizException(code=" + this.getCode() + ", message=" + this.getMessage() + ")";
    }
}
